<template>
  <div class="side">
    <div class="register">
      <el-row>
        <el-button type="primary" class="dakai" @click="createData">提交</el-button>
      </el-row>
    </div>
    <!-- 勾选 -->
    <el-form label-position="right" label-width="196px" ref="dataForm" :model="MessageSet">
      <div style="width:400px;height:32px;margin-top:20px;font-size:30px;margin-left:10px;line-height:20px;">
        <el-checkbox v-model="MessageSet.studentToStudent" label="允许学员给学员发送私信"></el-checkbox>
      </div>
      <div style="width:400px;height:32px;margin-top:20px;font-size:30px;margin-left:10px;line-height:20px;">
        <el-checkbox v-model="MessageSet.studentToTeacher" label="允许学员给教师发送私信"></el-checkbox>
      </div>
      <div style="width:400px;height:32px;margin-top:20px;font-size:30px;margin-left:10px;line-height:20px;">
        <el-checkbox v-model="MessageSet.teacherToStudent" label="允许教师给学员发送私信"></el-checkbox>
      </div>
    </el-form>
    <p style="width:542px;height:57px;font-size:14px;margin-left:32px;line-height:27px;color:#606266">提示：支持取消上述角色间互发私信功能，其余角色不影响。设置后仅APP端不生效。</p>
  </div>
</template>

<script>
  import {addMessageSet, getMessageSet} from '@/api/system/message_set';
  import {getTenantId} from '@/utils/auth';

  export default {
    data() {
      return {
        MessageSet: {
          studentToStudent: 0,
          studentToTeacher: 1,
          teacherToStudent: 1,
        }
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        getMessageSet(getTenantId()).then(response => {
          this.MessageSet = response.data
        }).catch(err => {
          console.log(err)
        })
      }
      ,
      createData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.MessageSet.tenantId = getTenantId();
            addMessageSet(this.MessageSet).then(() => {
              this.$notify({
                title: '成功',
                message: '创建成功',
                type: 'success',
                duration: 2000
              });
              this.fetchData();
            })
          }
        })
      }
    }
  }
</script>

<style>
  .register {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #e7e9ed;
    padding-top: 15px;
    padding-right: 34px;
  }

  .dakai {
    float: right;
    position: absolute;
    right: 10px;
    bottom: -25px;
  }
</style>
